#include <stdio.h>
#include <SDL.h>
int main(int argc, char *argv[]) {
    int done = 1;
	SDL_Surface *screen= NULL ,*fond = NULL;	//This pointer will reference the backbuffer
	SDL_Surface *image1=NULL,*image2=NULL,*image3=NULL,*image4=NULL,*image;	//This pointer will reference our bitmap sprite
    Uint8 *keystate;
    SDL_Rect posFond;

	//SDL_Surface *temp;//This pointer will temporarily reference our bitmap 	sprite
	//SDL_Rect src, dest;//These rectangles will describe the source and 	destination regions of our blit
	//We must first initialize the SDL video component, and check for success
	SDL_Event event;
	if (SDL_Init(SDL_INIT_VIDEO) != 0) {
		printf("Unable to initialize SDL: %s\n", SDL_GetError());
		return 1;
	}
	//Set the video mode to fullscreen 640x480 with 16bit colour and double-	buffering
	screen = SDL_SetVideoMode(798, 601, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
	if (screen == NULL) {
		printf("Unable to set video mode: %s\n", SDL_GetError());
		return 1;
	}

	//Load the bitmap into a temporary surface, and check for success
	image1 = SDL_LoadBMP("img/img0.bmp");
	if (image1 == NULL) {
		printf("Unable to load bitmap: %s\n", SDL_GetError());
		return 1;
	}
	SDL_WM_SetCaption("SUDOKU***SUDOKU***SUDOKU***SUDOKU***SUDOKU***SUDOKU***SUDOKU***SUDOKU",NULL);
	posFond.x=0;
	posFond.y=0;
	SDL_BlitSurface(image1, NULL , screen, &posFond);
	SDL_Flip(screen);
	SDL_FreeSurface(fond);



	while(done=1)
{

	//Blit the image to the backbuffer

SDL_UpdateRect(screen, 0, 0, 0, 0);

	while (SDL_PollEvent(&event))
{
	// check for messages
	switch (event.type)
	{
		// exit if the window is closed
		case SDL_QUIT:
		done = 0;
		break;
		// check for keypresses
		case SDL_KEYDOWN:
		{
			if (event.key.keysym.sym == SDLK_ESCAPE)
			{
            image1= SDL_LoadBMP("img/img0.bmp");
            image2=image3=image4=NULL;
            SDL_BlitSurface(image1, NULL , screen, &posFond);
            SDL_Flip(screen);


    }
			break;
		}
	} // end switch
	//****************partie facile**********************************************************
		keystate = SDL_GetKeyState(NULL);
	 if (keystate[SDLK_LEFT] ) {
            image2= SDL_LoadBMP("img/img2.bmp");
            image1=image3=image4=NULL;
            SDL_BlitSurface(image2, NULL , screen, &posFond);
             SDL_Flip(screen);

    }
    //*********************partie difficile***************************************************
    if (keystate[SDLK_RIGHT] ) {
    image3= SDL_LoadBMP("img/img3.bmp");
    image2=image1=image4=NULL;
    SDL_BlitSurface(image3, NULL , screen, &posFond);
            SDL_Flip(screen);


    }
    //*********************instruction*********************************************************
    if (keystate[SDLK_UP] ) {
   image1 = SDL_LoadBMP("img/img1.bmp");
   image2=image3=image4=NULL;
     SDL_BlitSurface(image1, NULL , screen, &posFond);
            SDL_Flip(screen);
  }

      //*******************quitter*************************************************************
	if (keystate[SDLK_DOWN] ) {
   image4= SDL_LoadBMP("img/img4.bmp");
   image2=image3=image1=NULL;
     SDL_BlitSurface(image4, NULL , screen, &posFond);
            SDL_Flip(screen);

//******************************************************************************************
    }
    if(keystate[SDLK_SPACE] && image1!=NULL)
        {
             image = SDL_LoadBMP("img/instructions.bmp");
             SDL_BlitSurface(image, NULL , screen, &posFond);
             SDL_Flip(screen);

             }
             if(keystate[SDLK_SPACE] && image2!=NULL)
        {
            image = SDL_LoadBMP("img/grille facile.bmp");
             SDL_BlitSurface(image, NULL , screen, &posFond);
             SDL_Flip(screen);
             done=2;

             }
             if(keystate[SDLK_SPACE] && image3!=NULL)
        {
            image = SDL_LoadBMP("img/grille difficile.bmp");
             SDL_BlitSurface(image, NULL , screen, &posFond);
             SDL_Flip(screen);
             done=3;
             }
    if(keystate[SDLK_SPACE] && image4!=NULL)
        {
             return 0;

             }


//SDL_Flip(screen);
} // end of message processing

}
//while ( done=2 )
//{
//}
//while (done=3)
   //{

  // }



	//Release the surface
	//SDL_FreeSurface(image);


	//Return success!
	return 0;

}
